# encoding=utf-8
import sys,os
import xml.dom.minidom as domm
import  Attribute
reload(sys)
sys.setdefaultencoding('utf-8')
class readxml():
    def __int__(self,dr):
        self.dr=dr
    def readXmlForAppium(self,readfile,att,writefile):
        Attribute.homeStory_story_notify_close_id
        isContuineWrite=True
        dom=domm.parse(readfile)
        rootdata=dom.documentElement
        itemlist=rootdata.getElementsByTagName('node')
        #判断文件是否存在
        if os.path.exists(writefile):
            isContuineStr = raw_input("文件已经存在是否重写？Y/N")
            if isContuineStr!="Y":
                isContuineWrite=False
            else:
                os.remove(writefile)
        if isContuineWrite:
            f = open(writefile, 'a+')
            f.write("# encoding=utf-8"+"\n"+"import sys,os"+"\n"+"reload(sys)"+"\n"+"sys.setdefaultencoding('utf-8')"+"\n")
            for item in itemlist:
                id=item.getAttribute(att)
                if id!="":
                    des = raw_input("属性"+att+"为："+id+"请输入注释信息: ")
                    if des!='':
                        name = raw_input("请输入命名: \n")
                        f.write("#" + des+"\n")
                        f.write(name+"=\"" + id + "\"" + "\n")
readxmlinfo=readxml()
readxmlinfo.readXmlForAppium("dumpForLogin.xml","resource-id","AttributeForLogin.py")